package com.daowen.uibuilder;

import com.daowen.bll.SystemParam;
import com.daowen.dal.DALBase;
import com.daowen.entity.Spcategory;

import java.text.MessageFormat;
import java.util.Iterator;
import java.util.List;

public class SpcategoryBuilder {


    public String BuildNavMenu(){

        StringBuffer sb=new StringBuffer();
        List<Spcategory> parentlist=DALBase.getEntity("spcategory", "where isleaf=0 ");

        for(Iterator<Spcategory> iterator = parentlist.iterator();iterator.hasNext();){

            Spcategory spc=iterator.next();
            sb.append("<dl>");
            //商品根类
            sb.append(MessageFormat.format("<dt>{0}</dt>",spc.getMingcheng()));
            sb.append("<dd>");

            List<Spcategory> listchild=DALBase.getEntity("spcategory", "where parentid="+spc.getId());

            for(Spcategory temchildspc : listchild){
                sb.append(MessageFormat.format("<a href=''{0}/e/shangpinlist.jsp?spcid={1}''>{2}</a>",SystemParam.getSiteRoot(),temchildspc.getId(),temchildspc.getMingcheng()));

            }

            sb.append("</dd>");

            //
            sb.append("</dl>");


        }
        return sb.toString();



    }


}
